package com.cx.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultUtil<T> {
    private Integer code;
    private String msg;
    private T data;

    public static ResultUtil success() {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(200);
        resultUtil.setMsg("成功");
        return resultUtil;
    }

    public ResultUtil(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResultUtil<T> success(T data) {
        ResultUtil<T> resultUtil = new ResultUtil<>();
        resultUtil.setCode(200);
        resultUtil.setMsg("成功");
        resultUtil.setData(data);
        return resultUtil;
    }

    public static <T> ResultUtil<T> success(T data, String msg) {
        ResultUtil<T> resultUtil = new ResultUtil<>();
        resultUtil.setCode(200);
        resultUtil.setMsg(msg);
        resultUtil.setData(data);
        return resultUtil;
    }

    public static ResultUtil error(String message) {
        ResultUtil resultUtil = new ResultUtil<>();
        resultUtil.setCode(201);
        resultUtil.setMsg(message);
        return resultUtil;
    }
}
